const Result = require("../src/utils/result");
const { logger } = require("./logger");

function errMiddleware(err, req, res, next) {
  logger(`${err.name}: ${err.message}`);
  if (err.name === "UnauthorizedError") {
    // 登录认证失败
    return res.send(new Result(401, "无效的token", null));
  }

  res.send(new Result(500, err.message, null));
}

module.exports = errMiddleware;